package com.xinruke.hostels.dailymanage.interfaces.api;

import com.xinruke.hostels.common.fallback.FeignFallback;
import com.xinruke.hostels.common.po.YwZhengjianxinxi;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.dailymanage.interfaces.dto.*;
import com.xinruke.hostels.dailymanage.interfaces.dto.inhotel.InHotelDetailQueryDTO;
import com.xinruke.hostels.dailymanage.interfaces.dto.inhotel.InHotelDetailQueryResultDTO;
import com.xinruke.hostels.dailymanage.interfaces.dto.inhotel.InHotelQueryByHotelIdDTO;
import com.xinruke.hostels.dailymanage.interfaces.dto.inhotel.InHotelQueryResultDTO;
import com.xinruke.hostels.dailymanage.interfaces.enums.ECommentScoreDescribe;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author GuoZheng
 * @ClassName DailyManageFallback
 * @date：2019/6/22
 * @version: V1.0.0
 * @description：评论熔断
 */
@Slf4j
@Component
public class DailyManageFallback implements FallbackFactory<DailyManageApi> {
    @Resource
    private FeignFallback feignFallback;

    @Override
    public DailyManageApi create(Throwable throwable) {
        log.error("系统异常：", throwable);

        return new DailyManageApi() {
            @Override
            public CommentAverageResultDto average(Integer id) {

                return  new CommentAverageResultDto(ECommentScoreDescribe.一般.getDescribe(), 0D);
            }

            @PostMapping("/comment/submit")
            @Override
            public ResultVO<String> submit(@Valid CommentSubmitInfoDto params) {
                return ResultVO.fail();
            }

            @Override
            public ResultVO<CommentDetailQueryResultDTO> detail(@Valid CommentDetailQueryDTO params) {
                return feignFallback.doFallback(DailyManageFallback.class, "detail", "评论详情出错");
            }

            @Override
            public ResultVO<RowsDataVO<CommentInfoQueryResultDTO>> list(@Valid CommentInfoQueryDto commentInfoQueryDto) {
                return feignFallback.doFallback(DailyManageFallback.class, "list", "查询评论列表出错");
            }

            @Override
            public ResultVO<Integer> queryRemainRoomCount(RemainCountQueryDto params) {
                return feignFallback.doFallback(DailyManageFallback.class, "queryRemainRoomCount", "查询剩余房数出错");
            }

            @Override
            public ResultVO<RoomReservationResultDTO> roomReservation(RoomReservationQueryDTO params) {
                return feignFallback.doFallback(DailyManageFallback.class, "roomReservation", "预订房间出错");
            }

            @Override
            public ResultVO saveGuest(YwZhengjianxinxi ywZhengjianxinxi) {
                return feignFallback.doFallback(DailyManageFallback.class, "saveGuest", "保存宾客信息出错");
            }

            @Override
            public ResultVO<RowsDataVO<CommentInfoQueryResultDTO>> allComment(@Valid CommentAllInfoQueryDTO commentAllInfoQueryDTO) {
                return feignFallback.doFallback(DailyManageFallback.class, "allComment", "不区分酒店查询全部评论出错");
            }

            @Override
            public ResultVO<String> del(@Valid CommentDelQueryDTO params) {
                return feignFallback.doFallback(DailyManageFallback.class, "del", "删除评论出错");
            }

            @Override
            public ResultVO<CommentDetailQueryResultDTO> centralDetail(@Valid CommentDetailQueryDTO params) {
                return feignFallback.doFallback(DailyManageFallback.class, "centralDetail", "查看评论详情出错");
            }

            @Override
            public ResultVO<String> audit(@Valid CommentAuditQueryDTO audit) {
                return feignFallback.doFallback(DailyManageFallback.class, "audit", "审核评论出错");
            }

        };
    }

}
